package com.anXin.article.listener;

import com.alibaba.fastjson.JSON;

import com.anXin.article.service.ArticleConfigService;
import com.anXin.common.constants.ArticleMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
@Slf4j
public class ArticleIsDownListener {

    @Resource
    private ArticleConfigService articleConfigService;

    @KafkaListener(topics = ArticleMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message){
        if (StringUtils.isNotBlank(message)){
            Map map = JSON.parseObject(message, Map.class);
            articleConfigService.updateByMap(map);
        }
    }
}
